package br.com.fox.iebav.dao;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.Query;

import br.com.fox.iebav.dao.abstractdao.AbstractDAO;
import br.com.fox.iebav.entity.Responsavelempresa;
import br.com.fox.iebav.entity.Usuarios;



@Stateless
public class ResponsavelEmpresaDAO extends AbstractDAO  {

	private Query q = null;

	public List<Responsavelempresa> findAll()
	{
		q = entityManager.createQuery("SELECT r FROM Responsavelempresa r ORDER BY r.nome ASC");
		@SuppressWarnings("unchecked")
		List<Responsavelempresa> list = q.getResultList();
		if(list.isEmpty())
			return new ArrayList<Responsavelempresa>();
		return list;
	}
		
	public Responsavelempresa login(String cpf,String senha)
	{
		q = entityManager.createQuery("SELECT r FROM Responsavelempresa r WHERE " +
				"r.cpf = :cpf AND " +
				"r.senha = :senha");
		
		q.setParameter("cpf", cpf);
		q.setParameter("senha", senha);
		@SuppressWarnings("unchecked")
		List<Responsavelempresa> list = q.getResultList();
		if(list.isEmpty())
			return null;
		else
		{
			Responsavelempresa r = list.get(0);
			return r;
		}
	}
}
